<?php
/*
 *   This file is part of Verbum.
 *
 *   Verbum is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   poat is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with poat.  If not, see <http://www.gnu.org/licenses/>.
 * 
 *   Copyright (c) 2008 Sergio Gabriel Teves <gabriel.sgt at gmail.com>
 */ 

switch ($op) {
	case "scan":
		set_time_limit(3600);
		$m = new message;
		$m->userid=$CURRENT_USER->userid;
		//while (true) {
			$list = $loader->loadList($m);
			if (count($list)>0) {
				out(jsonList($list,array("userid","#message","from","sent")));
				flush();
				$loader->execute($m->deleteAll($list));
				break;
			} else {
				//sleep(2);
			}
			//usleep(20000);
		//}
		break;
	default:
		$u = new user;
		$u->teamid = getTeamId($CURRENT_USER);
		$u->status = STATUS_ACTIVE;
		$ulist = $loader->loadListBy($u,$u->listByFilters());
		
		$list = array();
		foreach($ulist as $u) {
			if ($u->userid!=$CURRENT_USER->userid) {
				$obj = new stdClass;
				$obj->id=$u->userid;
				if (String::isEmpty($u->name)) {
					$obj->text = $u->userid;	
				} else {
					$obj->text = $u->name . " (".$u->userid.")";
				}
				$obj->iconCls = "user-type-".strtolower($u->groupid);
				$obj->leaf=true;
				$list[] = $obj;		
			}
		}
		$res = jsonEncodeList($list,array("id","text","iconCls","~leaf"),null);
		out("[".$res."]");
		break;
}

?>

 